import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/tour_user";

export const fx_shop_home_api = (
  data: { guider_id: string },
  showError = true
) => {
  return Http.get<{
    shop_info: any;
    banner: any[];
    recommend: any[];
    tour_count: number;
    passport_count: number;
    course_count: number;
    shop_count: number;
    wenbo_count: number;
  }>(`/v3${baseUrl}/fx_shop_home`, data).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const fx_shop_get_recommend_list_api = (
  data: { guider_id: string } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(
    `/v3${baseUrl}/fx_shop_get_recommend_list`,
    data
  ).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const fx_shop_tour_header_api = (
  data: { guider_id: string },
  showError = true
) => {
  return Http.get<{
    in_china: any[];
    out_china: any[];
    is_china_count: number;
    is_out_china_count: number;
    is_foreign_count: number;
    is_public_welfare_count: number;
  }>(`/v3${baseUrl}/fx_shop_tour_header`, data).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const fx_shop_tour_list_api = (
  data: {
    guider_id: string;
    type: number;
    id?: string;
  } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(
    `/v3${baseUrl}/fx_shop_tour_list`,
    data
  ).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const fx_shop_passport_list_api = (
  data: { guider_id: string } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(
    `/v3${baseUrl}/fx_shop_passport_list`,
    data
  ).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const fx_shop_course_list_api = (
  data: { guider_id: string } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(
    `/v3${baseUrl}/fx_shop_course_list`,
    data
  ).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const fx_shop_wenbo_list_api = (
  data: { guider_id: string } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(
    `/v3${baseUrl}/fx_shop_wenbo_list`,
    data
  ).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const fx_shop_shop_list_api = (
  data: { guider_id: string } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(
    `/v3${baseUrl}/fx_shop_shop_list`,
    data
  ).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const fx_shop_search_api = (
  data: { guider_id: string; keyword: string },
  showError = true
) => {
  return Http.get<{
    tour: any[];
    passport_guide: any[];
    passport_shop: any[];
    course: any[];
  }>(`/v3${baseUrl}/fx_shop_search`, data).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const fx_shop_get_all_selected_api = (
  data: { guider_id: string } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(
    `/v3${baseUrl}/fx_shop_get_all_selected`,
    data
  ).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};
